<template>
    <div class="ele-body">
        <el-card shadow="never">
            <!-- 数据表格 -->
            <el-table :data="tableData" border style="width: 100%" :height="tableHeight">
                <el-table-column label="周期" prop="cycle" align="center"></el-table-column>
                <el-table-column label="状态" width="120" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.status==1">生成中</div>
                        <div v-else-if="scope.row.status==2">已生成</div>
                    </template>
                </el-table-column>
                <el-table-column label="生成时间" prop="add_time" width="240" align="center"></el-table-column>
                <el-table-column label="操作" width="160" align="center">
                    <template slot-scope="scope">
                        <el-link type="primary" v-if="scope.row.status==2" @click="templateImport(scope.row)">下载</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>
<script>
    export default {
        data(){
            return{
                tableData:[],
                tableHeight:'calc(100vh - 160px)',
            }
        },
        created(){
            this.queryTable()
        },
        mounted(){

        },
        methods:{
            // 导入模板
            templateImport(row) {
                window.location.href = process.env.VUE_APP_API_BASE_URL + row.file
            },
            queryTable(){
                this.$http.post('/Exportqueue/index',{model:'order'}).then(res=>{
                    if(res.data.code=== 0 ){
                        this.tableData=res.data.data
                        this.tableData.forEach(item=>{
                            item.add_time=this.timestampToTime(item.add_time)
                        })
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            timestampToTime(timestamp) { 
                const date = new Date(timestamp * 1000); 
                const Y = date.getFullYear() +'年'; 
                const M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) +'月'; 
                const D = date.getDate() +'日'; 
                const h = date.getHours() +'时'; 
                const m = date.getMinutes() +'分'; 
                const s = date.getSeconds() +'秒'; 
                return Y+M+D+h+m+s; 
            } 
        },
    }
</script>

<style scoped></style>